package www.qiyue.kc;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class FeePlanTest {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("feeplantest")
    public void test(){
        String sql = "SELECT * from ais_fee_plan WHERE id like '0b44571e55c328e00155f682cf2e0%' and contract_id is NULL";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : list) {
            String contract_code = map.get("contract_code") + "";
            String id = map.get("id") + "";
            boolean b = StrUtil.containsBlank(contract_code);
            if (true){
                System.out.println("contract_code = " + contract_code);
                //String replace = contract_code.replace("-", "%");
                String replace = contract_code.split("-")[0]+"%";
                String[] split = contract_code.split("-");
                String replace2 = "%"+contract_code.split("-")[split.length-1]+"%";
                //System.out.println("replace = " + replace);
                String contractSql = "SELECT * from ais_contract WHERE contract_code LIKE '"+replace+"' and contract_code like '"+replace2+"'";
                List<Map<String, Object>> list1 = jdbcTemplate.queryForList(contractSql);
                if (list1.size()==1){
                    String contract_id = list1.get(0).get("id") + "";
                    String update = "UPDATE ais_fee_plan set contract_id = '"+contract_id+"' WHERE id ='"+id+"'";
                    jdbcTemplate.update(update);
                }

            }
        }
    }
}
